﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using GrayParrot.Web.Controls;
using GrayParrot.Core.Filters;
using FimetContoDeposito.DAL;
using FimetContoDeposito.BLL.Objects;

namespace FimetContoDeposito.BLL.ResultSets
{
    public class MovimentiScaricoResultSet : ResultSet<MovimentoBag>
	{
        public MovimentiScaricoResultSet(DTParameters param, IQueryable<MovimentoBag> result)
            : base(param, result)
        {
        }

        public override Expression<Func<MovimentoBag, bool>> ApplyGeneralFilter(string searchPattern)
        {
            var predicate = PredicateBuilder.False<MovimentoBag>();

            //if (!string.IsNullOrWhiteSpace(searchPattern))
            //{
            //    predicate = predicate.Or(im => im.NumeroDDT != null && im.NumeroDDT.ToString().Contains(searchPattern));
            //    predicate = predicate.Or(im => im.Cliente != null && im.Cliente.ToString().Contains(searchPattern));
            //    predicate = predicate.Or(im => im.DataDDT != null && im.DataDDT.ToString().Contains(searchPattern));
            //    predicate = predicate.Or(im => im.TipoMovimento != null && im.TipoMovimento.ToString().Contains(searchPattern));
            //}

            return predicate;
        }

        public override Expression<Func<MovimentoBag, bool>> ApplyGeneralColumnsFilter(List<string> columnSearch)
        {
            var predicate = PredicateBuilder.True<MovimentoBag>();

            //                    //            <cc1:ColumnFilter ColumnName="NumeroDDT" Type="Text" />
            //                    //<cc1:ColumnFilter ColumnName="DataDDT" Type="Text" />
            //                    //<cc1:ColumnFilter ColumnName="Cliente" Type="Text" />
            //                    //<cc1:ColumnFilter ColumnName="Articolo" Type="Text" />
            //                    //<cc1:ColumnFilter ColumnName="TipoMovimento" Type="Text" />
            //                    //<cc1:ColumnFilter ColumnName="Descrizione" Type="Text" />

            //string m_id = columnSearch[ColumnIndex];
            //string m_numeroDDT = columnSearch[ColumnIndex];
            //DateTime m_dataDDT = default(DateTime);
            //if (columnSearch[2] != null)
            //{
            //    m_dataDDT = GrayParrot.Extensions.Types.TypeExtensions.GetValueOrDefault<DateTime>(columnSearch[ColumnIndex]);
            //}
            //string m_cliente = columnSearch[ColumnIndex];
            //string m_articolo = columnSearch[ColumnIndex];
            //string m_tipoMovimento = columnSearch[ColumnIndex];

            //if (!string.IsNullOrWhiteSpace(m_numeroDDT))
            //{
            //    predicate = predicate.And(im => im.NumeroDDT.Contains(m_numeroDDT));
            //}

            //if (m_dataDDT != default(DateTime))
            //{
            //    predicate = predicate.And(im => im.DataDDT.Equals(m_dataDDT));
            //}

            //if (!string.IsNullOrWhiteSpace(m_cliente))
            //{
            //    predicate = predicate.And(im => im.Cliente.Contains(m_cliente));
            //}

            //if (!string.IsNullOrWhiteSpace(m_articolo))
            //{
            //    predicate = predicate.And(im => im.Articolo.Contains(m_articolo));
            //}

            ////if (!string.IsNullOrWhiteSpace(m_tipoMovimento))
            ////{
            ////    predicate = predicate.And(im => im.TipoMovimento.Equals( == m_tipoMovimento);
            ////}

            return predicate;
        }
	}
}
